package com.lezhu.plugin;

import android.content.Intent;
import android.widget.Toast;


import com.baidu.android.pushservice.PushManager;
import com.baidu.android.pushservice.PushMessageReceiver;
import com.baidu.android.pushservice.PushConstants;
import com.fangbaba.crm.PushReceiver;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginEntry;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Arrays;
import java.util.List;

/**
 * Created by zhaoshengbo on 16/2/16.
 */
public class PushPlugin extends CordovaPlugin {

    private static final String ACTION_INIT = "init";

    private static final String ACTION_START_WORK = "startWork";

    private static final String ACTION_STOP_WORK = "stopWork";

    public PushPlugin() {
        this.getClass();
    }

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if (ACTION_INIT.equals(action)) {
            LZNotifyListener.setCallbackContext(callbackContext);
        } else if (ACTION_START_WORK.equals(action)) {
            PushManager.startWork(webView.getContext(), PushConstants.LOGIN_TYPE_API_KEY, "5UZCVDmMEs9DSoCISOEQGwOm");
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, PushReceiver.CHANNEL_ID);
            callbackContext.sendPluginResult(pluginResult);
        } else if (ACTION_STOP_WORK.equals(action)) {
            PushManager.stopWork(webView.getContext());
            PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, "ok");
            callbackContext.sendPluginResult(pluginResult);
        }else{

        }
        return true;
    }

}

